#!/usr/bin/env python3

import os
import gi
gi.require_version('Gtk', '3.0')
gi.require_version('AyatanaAppIndicator3', '0.1')
from gi.repository import Gtk, AyatanaAppIndicator3

APPINDICATOR_ID = "random-background"

def script1(widget):
    os.popen("`sh -c /usr/share/random-background/kde/data/scripts/change`")

def script2(widget):
    os.popen("/usr/share/random-background/kde/data/chooser.py")

def script3(widget):
    os.popen("$HOME/.random-background/wallpaper_net.py")

def script4(widget):
    os.popen("/usr/share/random-background/kde/data/net/save_pic.py")

def script5(widget):
    os.popen("/usr/share/random-background/kde/data/scripts/settings")

def script6(widget):
    os.popen("/usr/share/random-background/icons/about/about.py")

def script7(widget):
    os.popen("pkill -f 'Random Background'")
    os.popen("rm -f /tmp/tmp* > /dev/null 2>&1")

def build_menu():
    menu = Gtk.Menu()
    items = [
        ("🔰️ Change", script1, "Change Current Image"),
        ("🏞️ Choose", script2, "Select A Image"),
        ("🌐️ Download", script3, "Change Download Image"),
        ("📂️ Save", script4, "Save Download Image"),
        ("⚙️ Settings", script5, "Change Background Settings"),
        ("❓️ About", script6, "About Random Background"),
        ("❌️ Quit", script7, "Quit Recorder"),

    ]

    for label, callback, tip in items:
        item = Gtk.MenuItem(label=label)
        item.connect('activate', callback)
        item.set_tooltip_text(tip)
        menu.append(item)

    menu.show_all()
    return menu

indicator = AyatanaAppIndicator3.Indicator.new(
    APPINDICATOR_ID,
    "/usr/share/icons/hicolor/48x48/apps/random-background.png",
    AyatanaAppIndicator3.IndicatorCategory.APPLICATION_STATUS
)

indicator.set_status(AyatanaAppIndicator3.IndicatorStatus.ACTIVE)
indicator.set_menu(build_menu())

Gtk.main()

